import table from '@/components/dt/table/render.js'
import Opt from '@/components/dt/info/Opt.js'
let _this = null
class Column extends Opt {
  constructor(vm) {
    super()
    _this = vm
    this.build()
  }

  build() {
    this.createAll()
    this.opts.push(...this.all)
  }

  createAll() {
    this.all = [
      {
        title: '序号',
        type: 'index',
        width: 80,
        align: 'center'
      },
      {
        title: '活动名称',
        field: 'name',
        minWidth: 150
      },
      {
        title: '活动终端',
        field: 'terminal',
        minWidth: 150
      },
      {
        title: '活动范围',
        field: 'companyDesc',
        minWidth: 150
      },
      {
        title: '活动形式',
        field: 'activityType',
        minWidth: 100,
        slots: {
          default: (params, h) => {
            return params.row.activityType == 'GOLDEN_EGG' ? '砸金蛋' : ''
          }
        }
      },
      {
        title: '活动开始时间',
        field: 'startDate',
        minWidth: 150
      },
      {
        title: '活动结束时间',
        field: 'endDate',
        minWidth: 150
      },
      {
        title: '活动浏览量(PV)',
        field: 'viewCount',
        minWidth: 150
      },
      {
        title: '访客数(UV)',
        field: 'participantsNumber',
        minWidth: 150
      },
      {
        title: '状态',
        field: 'status',
        minWidth: 150,
        cell: {
          text: {
            type: 'dict',
            key: 'acBasicsStatus'
          }
        }
      },
      {
        title: '创建日期',
        field: 'createTime',
        minWidth: 150
      },
      {
        title: '操作',
        fixed: 'right',
        width: 290,
        align: 'center',
        slots: {
          default: (params, h) => {
            let btns = []
            if (params.row.status != 'UNPUBLISHED') {
              btns.push({
                title: '预览',
                event: 'checkFun',
                data: params.row
              })
            }

            btns.push({
              title: _this.unlocking('0215010200') ? '编辑' : '',
              event: 'editFun',
              data: params.row
            })

            if (params.row.status == 'NO_START' || params.row.status == 'UNDER_WAY') {
              btns.push({
                title: _this.unlocking('0215010500') ? '强制结束' : '',
                event: 'closeActivity',
                data: params.row
              })
            }

            if (params.row.status == 'END' || params.row.status == 'UNDER_WAY') {
              btns.push({
                title: _this.unlocking('0215010600') ? '活动数据' : '',
                event: 'getActivityData',
                data: params.row
              })
            }

            if (params.row.status == 'UNPUBLISHED') {
              btns.push({
                title: _this.unlocking('0215010300') ? '删除' : '',
                event: 'delActivity',
                data: params.row
              })
            }

            btns.push({
              title: _this.unlocking('0215010400') ? '复制活动' : '',
              event: 'copyActivity',
              data: params.row
            })

            return table.cell.btns(_this, h, btns)
          }
        }
      }
    ]
  }
}

export default Column
